
<template>
  <div class="execution">
    <basic-container>
      <avue-form
        ref="form"
        v-model="searchForm"
        :option="option"
      >
        <template slot="menuForm">
          <el-button
            :loading="loading"
            v-if="permissionList.generate"
            type="primary"
            @click="dataExport"
          >生成日报表</el-button>
        </template>
      </avue-form>
    </basic-container>
  </div>
</template>

<script>
import { listSettleCycle4Generate, generate } from '@/api/rca/swckstationdailyreporgenerate'
import { handleExcelResponse, getQueryString } from "@/util/util";
import { mapGetters } from 'vuex'

export default {
  name: 'viewckdataauditreportcheck',
  data () {
    return {
      cycleOptions: [],
      loading: false,
      searchForm: {
        settleCycle: null,
      },
    }
  },
  computed: {
    option () {
      return {
        emptyBtn: false,
        submitBtn: false,
        column: [{
          label: "日期",
          prop: "settleCycle",
          type: "daterange",
          valueFormat: 'yyyy-MM-dd',
          rules: [{
            required: true,
            message: "请选择日期",
            trigger: "blur"
          }]
        }]
      }
    },
    ...mapGetters(['permissions']),
    permissionList () {
      return {
        generate: this.vaildData(this.permissions.sw_ck_station_daily_report_generate, false),
      };
    }
  },
  created () {
  },
  methods: {
    async dataExport () {
      if(!this.searchForm.settleCycle){
        this.$message.error('日期不能为空')
        return
      }
      const [startDate, endDate] = this.searchForm.settleCycle
      this.loading = true;
      await generate({startDate, endDate});
      this.$message.success('操作成功！报表生成需要一定时间，请稍后查看')
      this.loading = false;
    },
  }
}
</script>
